﻿using System.Web.Routing;
using EPiServer.Common.Categories;

namespace JoelAbrahamsson.Web.ExtensionMethods
{
    public static class CategoryExtensions
    {
        public static string GetUrl(this ICategory category, RequestContext context)
        {
            return "http://"
                + System.Configuration.ConfigurationManager.AppSettings["defaultDomain"]
                + RouteTable.Routes.GetVirtualPath(context, new RouteValueDictionary(new
                     {
                         mainCategoryName = category.Parent.GetSlug(), 
                         subCategoryName = category.GetSlug(), 
                         controller = "Archive", 
                         action = "Category"
                     })
                     ).VirtualPath;
        }

        public static string GetSlug(this ICategory category)
        {
            return category.Name
                .Replace(" ", "-")
                .Replace("#", "sharp");
        }
    }
}
